<#--数据库表属性结构面板-->
<div id="databaseTableTree" class="tree">
	<div class="tree-folder" style="display: none;">
		<div class="tree-folder-header">
			<i class="fa fa-folder yellow"></i>
			<div class="tree-folder-name"></div>
		</div>
		<div class="tree-folder-content"></div>
		<div class="tree-loader" style="display: none;"></div>
	</div>
	<div class="tree-item" style="display: none;">
		<i class="tree-dot"></i>
		<div class="tree-item-name"></div>
	</div>
</div>
<script type="text/javascript">
<!--
var AjaxDataSourceTree = function(options) {
		this._data = options.data;
		this._delay = options.delay;
		this._loadData = options.loadData;
		this._isInit = false;
	};
	AjaxDataSourceTree.prototype = {
		data : function(options, callback) {
			if (options.params && options.params.uuid) {
				console.log(options.params.uuid);
			}
			var self = this;
			if (self._isInit && self._loadData
					&& (typeof self._loadData === "function")) {
				self._loadData(options, function(data) {
					if (!data) {
						data = [];
					}
					callback({
						data : data
					});
				});
			} else {
				setTimeout(function() {
					var data = $.extend(true, [], self._data);
					var childrenData = options.data;
					if (childrenData) {
						if (childrenData.length > 0) {
							data = childrenData;
						} else {
							data = [];
						}
					}
					callback({
						data : data
					});
					self._isInit = true;
				}, this._delay);
			}
		}
	};
	/**
	 * 延迟加载数据库表
	 */
	function loadAjaxTree(treeId, catalog, setDataCallback) {
		var url = "codeGenerateController/getAllTable.do";
		if (!catalog) {
			catalog = "";
		}
		var params = {
			catalog : catalog
		};
		ajaxRequest(url, params, function(data) {
			if (data.resCode == "200") {
				var treeData = eval("(" + data.data + ")");
				console.log(treeData);
				if (setDataCallback && (typeof setDataCallback === "function")) {
					setDataCallback(treeData);
				} else {
					var databaseTableTreeAjaxDataSourceTree = new AjaxDataSourceTree({
						data: treeData,
						delay: 100,
						loadData: function(option, callback) {
							var nowCatalog = "";
							console.log(option.params);
							if (option.params && option.params.catalog) {
								nowCatalog = option.params.catalog;
							}
							loadAjaxTree(treeId, nowCatalog, callback);
						}
					});
					$("#" + treeId).tree({
						cacheItems: true,
						selectable: true,
						dataSource: databaseTableTreeAjaxDataSourceTree,
						loadingHTML: '<div class="tree-loading"><i class="fa fa-rotate-right fa-spin"></i></div>'
					});
				}
			} else {
				ajaxError(data.resMsg);
			}
		},
		function(XMLHttpRequest, textStatus, errorThrown) {
			ajaxError(errorThrown);
		}, "GET", "JSON");
	}
//-->
</script>
